package training.irpf.presentation;

import java.math.BigDecimal;

import javax.faces.bean.ManagedBean;

import training.irpf.business.IRPFData;
import training.irpf.business.calc.CalculadoraIrpf;
import training.irpf.business.taxtable.TabelaIrpf2012;

@ManagedBean
public class FormImposto {
	
	private IRPFData form;
	
	public FormImposto(){
		this.form = new IRPFData();
	}

	public IRPFData getForm() {
		return form;
	}

	public void setForm(IRPFData form) {
		this.form = form;
	}
	
	public void calculate(){
		System.out.println("chegou!");
		TabelaIrpf2012 tabela = new TabelaIrpf2012();
		CalculadoraIrpf calc = new CalculadoraIrpf(tabela);
		
		BigDecimal base;
		
		try{
			base = new BigDecimal(form.getBase());
			
			form.setAliquota(tabela.buscarAliquota(base));
			form.setDeducao(tabela.buscarParcela(base));
			
			form.setImposto(calc.calculaIrpf(base).toString());
		}catch (Exception e){
			e.printStackTrace();
		}
		
		
	}
	
}
